var app = getApp()
Page({
  data: {
    useData: "",
    goodsId: ""
  },
  // 删除
  delect: function (res) {
    var that = this;
    console.log(res.currentTarget.dataset.goodsid)
    let id = res.currentTarget.dataset.goodsid
    wx.showModal({
      title: '删除商品',
      content: '确认删除商品吗？',
      showCancel: true,
      cancelText: '取消删除',
      cancelColor: 'black',
      confirmText: '确认删除',
      confirmColor: 'red',
      success: function (res) {
        if (res.confirm) {
          console.log('删除成功')
          wx.request({
            url: 'http://123.206.228.246:50080/wxone/goods/deleteById',
            method: 'POST',
            data: {
              goodsId: that.data.goodsId
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success: (res) => {
              console.log(res)
              wx.reLaunch({
                url: '../index/index',
              })
            }
          })
        } else if (res.cancel) {
          console.log('取消删除')
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  // 跳转到编辑界面
  upProject: function (res) {
      console.log(res)
      console.log(res.currentTarget.dataset.id)
      app.globalData.goodsId = res.currentTarget.dataset.id
      console.log(app.globalData.goodsId)
    wx.redirectTo({
      url: '../bianji/bianji?goodsId=' + this.data.goodsId,
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.goodsId)
    this.setData({
      goodsId: options.goodsId
    })
    wx.request({
      url: 'http://123.206.228.246:50080/wxone/goods/goodsDetails',
      method: 'POST',
      data: {
        goodsId: this.data.goodsId
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: (res) => {
        console.log(res)
        this.setData({
          useData: res.data.data
        })
      }
    })
    this.setData({
      index: options.index,
      goodsId: options.goodsId
    })
  },
})